package com.syni.mdd.yhd.common.all.dao.jpa;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.BmsUserVideoLike;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface BmsUserVideoLikeDao extends BaseJPADao<BmsUserVideoLike,Integer> {
    List<BmsUserVideoLike> findByBmsUserIdAndBmsVideoId(Integer userId,Integer videoId);

    List<BmsUserVideoLike> findByBmsUserIdAndBmsVideoIdIsIn(Integer userId, Set videoId);

    @Query(value = "select * from bms_user_video_like buvl left join bms_video bv on buvl.bms_video_id = bv.id " +
            " where buvl.bms_user_id = ?1 and bv.is_delete = 0",nativeQuery = true)
    List<BmsUserVideoLike> findByBmsUserId(Integer userId, Pageable pageable);

    List<BmsUserVideoLike> findByBmsUserId(Integer userId);

    List<BmsUserVideoLike> findByBmsUserId(Integer userId, Sort sort);

    List<BmsUserVideoLike> findByBmsUserIdOrderByLikeTime(Integer userId,Pageable pageable);

    @Query(value = "select buvl.id,buvl.bms_video_id,buvl.bms_user_id from bms_user_video_like buvl where buvl.bms_video_id in (?1)" +
            "order by buvl.bms_video_id desc,buvl.like_time desc",nativeQuery = true)
    List<Map<String,Object>> selfFindByVideoIds(Set videoIds);

    @Query(value = "select buvl.id,buvl.bms_video_id,buvl.bms_user_id from bms_user_video_like buvl where buvl.bms_user_id = ?1 and buvl.bms_video_id in (?2)",nativeQuery = true)
    List<Map<String,Object>> selfFindByUserIdAndVideoIds(Integer userId,Set videoIds);

    @Query(value = "select buvl.id from bms_user_video_like buvl where buvl.bms_video_id = ?1 limit 0,1",nativeQuery = true)
    Map<String,Object> selfFindBmsVideoIdExist(Integer videoId);

    @Query(value = "select count(buvl.id) num,buvl.bms_user_id from bms_user_video_like buvl " +
            "left join bms_video bv on buvl.bms_video_id = bv.id where buvl.bms_user_id = ?1 and bv.is_delete=0",nativeQuery = true)
    Map<String,Object> selfCountUserLikeNum(Integer userId);
}
